/**
 * 自定义hooks之useUnmount
 */

import { useEffect, useRef } from "react";

type Fn = () => void;

function useUnmount(fn: Fn) {
  const ref = useRef<Fn>();
  ref.current = fn;

  useEffect(() => {
    return () => {
      ref.current?.();
    };
  }, []);
}

export default useUnmount;
